package cn.slipi.pan.common.util;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileUtil {
    public static String getResourcePath(String dir) {
        URL resourceUrl = FileUtil.class.getResource(String.format("/%s/", dir));
        if (resourceUrl != null) {
            try {
                Path resourceDirPath = Paths.get(resourceUrl.toURI());
                return resourceDirPath.toString();
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("Resource directory not found.");
        }
        return "";
    }

    public static String getFilePath(String dir, String filename) {
        String versionPath = FileUtil.getResourcePath(dir);
        return versionPath + File.separator + filename;
    }
}
